/**
 * 我的购物车
 * @param {Int} uid [用户id]
 */
function myGoodscart(uid){
	$.ajax({
		type:"post",  
		url:apiRoot + "/Home/Goodscart/myGoodscart/", 
		data:{
			uid :  uid 
		}, 
		beforeSend:function(){
			plus.nativeUI.showWaiting('加载中...');
		}, 
		complete:function(){
			plus.nativeUI.closeWaiting();
		},
		dataType:'json',
   		success : function(data){      
   			$('.total').text(data.length);
    	},
   		error :function(e){
   			errorPrompt(e);	
   		}
   	})
}





/**
 * 加入购物车
 * @param {Int} uid [用户id]
 * @param {Int} aid [书籍id]
 * @param {String} name [书籍名称]
 * @param {Float} price [价格]
 * @param {String} author [作者]
 * @param {String} litpic [图片]
 * @param {Float} discountprice [折扣价]
 */
function addGoodscart(uid , aid , name , price , author , litpic , discountprice ){
//	console.log(apiRoot + "/Home/Goodscart/addGoodscart/uid/" +uid+'/aid/'+ aid +'/name/'+ name +'/price/'+ price +'/author/'+ author +'/litpic/'+ litpic +'/discountprice/'+ discountprice);return;
	$.ajax({
		type:"post",  
		url:apiRoot + "/Home/Goodscart/addGoodscart/", 
		data:{
			uid :  uid ,
			aid : aid ,
			name : name,
			price : price,
			discountprice : discountprice,
			author : author,
			litpic : litpic
		},
		beforeSend:function(){
			plus.nativeUI.showWaiting('加载中...');
		},
		complete:function(){
			plus.nativeUI.closeWaiting();
		},
 		success : function(data){
 			if(data == -1){
 				toast('购物车已有该书籍了');
 			}else if(data == -2){
 				toast('您已购买过本书籍，无需购买');
 			}else{
 				toast('添加成功');
 				if(self.page){
					mui.fire(plus.webview.getWebviewById(self.page) , 'update_goodscart' , {
						num : -1
					})
				}else{
	 				$('.total').text(parseInt($('.total').text()) +1 );
				}
 			}
 		},
 		error :function(e){
 			errorPrompt(e);	
 		}
 	})
	
}



/**
 * 监听购物车数量的更新
 */
window.addEventListener('update_goodscart_info' , function(result){
	myGoodscart(result.detail.uid);
})